﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DisplayBoardInfo.Server.Session.MessageHandlers
{
    class SessionHandler : MessageHandler
    {
        Network.Messages.NetworkMessage message;
        DataManager dm;

        public SessionHandler(Network.Messages.NetworkMessage message, DataManager dm)
        {
            this.message = message;
            this.dm = dm;
        }

        public override Network.Messages.NetworkMessage GetResult()
        {
            if (message.Type == Network.Messages.NetworkMessageTypes.Session_Start)
            {
                dm.CurrentStatus = SessionStatus.Przyjmuje;
            }
            else if (message.Type == Network.Messages.NetworkMessageTypes.Session_Pause)
            {
                dm.CurrentStatus = SessionStatus.Przerwa;
                dm.Powod = message.Content.ToString();
            }
            else if (message.Type == Network.Messages.NetworkMessageTypes.Session_End)
            {
                dm.CurrentStatus = SessionStatus.NiePrzyjmuje;
            }
            else if (message.Type == Network.Messages.NetworkMessageTypes.Session_Continue)
            {
                dm.CurrentStatus = SessionStatus.Przyjmuje;
            }
            else if (message.Type == Network.Messages.NetworkMessageTypes.Session_ChangeList)
            {
                dm.Appointments = (IEnumerable<Network.Messages.Content.Appointment>)message.Content;
            }
            else if (message.Type == Network.Messages.NetworkMessageTypes.Session_NextPatient)
            {
                List<Network.Messages.Content.Appointment> apps = new List<Network.Messages.Content.Appointment>((IEnumerable<Network.Messages.Content.Appointment>)message.Content);
                if (apps.Count > 0)
                {
                    Network.Messages.Content.Appointment first = apps.First();
                    apps.Remove(first);
                    dm.Appointments = apps;
                    dm.InRoomPatient = first.Patient;
                }
                
            }

            return new Network.Messages.NetworkMessage(Network.Messages.NetworkMessageTypes.OK, "ok");
        }
    }
}
